package cn.kgm.makeGod;

import cn.kgm.makeGod.condition.WorldState;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-11 18:05
 * @Description: cn.kgm.makeGod.WorldInitializer
 */
public class WorldInitializer {

    public static void initializeItems(WorldState world) {
        // 创建万年蛇胎酒
        Item snakeWine = new Item(1, "万年蛇胎酒", ItemType.CONSUMABLE, 1000,
                "传说中的仙酿，由万年蛇胎浸泡而成，饮用后可大幅提升修为");
        snakeWine.addEffect("level", 5);
        snakeWine.addEffect("luck", 10);
        world.addItem(snakeWine);

        // 高级丹药
        Item advancedPill = new Item(2, "九转金丹", ItemType.CONSUMABLE, 500,
                "高级修炼丹药，能显著提升修为");
        advancedPill.addEffect("level", 3);
        advancedPill.addEffect("maxHp", 20);
        world.addItem(advancedPill);

        // 灵草
        Item spiritHerb = new Item(3, "七星灵草", ItemType.MATERIAL, 100,
                "蕴含北斗七星灵气的草药，是炼制高级丹药的材料");
        world.addItem(spiritHerb);

        // 上古法宝
        Item ancientArtifact = new Item(4, "混沌钟", ItemType.TREASURE, 2000,
                "上古遗留的法宝，拥有莫测的威力");
        ancientArtifact.addEffect("attack", 30);
        ancientArtifact.addEffect("defense", 20);
        ancientArtifact.addEffect("luck", 15);
        world.addItem(ancientArtifact);

        // 珍稀材料
        Item rareMaterial = new Item(5, "星辰铁", ItemType.MATERIAL, 400,
                "天外陨铁，蕴含星辰之力，是炼制神兵利器的绝佳材料");
        world.addItem(rareMaterial);

        // 疗伤药
        Item healingPotion = new Item(6, "生生造化丹", ItemType.CONSUMABLE, 150,
                "极品疗伤药物，可以迅速恢复生命值");
        healingPotion.addEffect("currentHp", 100);
        world.addItem(healingPotion);

        // 添加土遁符
        EarthEscapeTalisman earthTalisman = new EarthEscapeTalisman(
                7, "土遁符", 300,
                "一种神奇的符咒，使用后可以瞬间土遁逃离危险，逃脱概率与对手实力差距相关",
                40, 3 // 基础逃脱概率40%，最大逃脱距离3个地点
        );
        world.addItem(earthTalisman);

        // 添加高级土遁符
        EarthEscapeTalisman advancedEarthTalisman = new EarthEscapeTalisman(
                8, "高级土遁符", 600,
                "强化版的土遁符，拥有更高的逃脱概率和更远的逃脱距离",
                60, 5 // 基础逃脱概率60%，最大逃脱距离5个地点
        );
        world.addItem(advancedEarthTalisman);
    }


    public static void initializeResourceNodes(WorldState world) {
        // 创建酒馆资源点（产出万年蛇胎酒）
        Location tavern = findLocationByType(world, LocationType.TAVERN);
        if (tavern != null) {
            ResourceNode wineNode = new ResourceNode(1, "陈年酒窖", tavern, 1, 6);
            world.addResourceNode(wineNode);
        }

        // 创建炼丹房资源点（产出九转金丹）
        Location alchemyRoom = findLocationByName(world, "炼丹房");
        if (alchemyRoom != null) {
            ResourceNode pillNode = new ResourceNode(2, "丹炉", alchemyRoom, 2, 8);
            world.addResourceNode(pillNode);
        }

        // 创建野外资源点（产出七星灵草）
        Location wild = findLocationByType(world, LocationType.WILD);
        if (wild != null) {
            ResourceNode herbNode = new ResourceNode(3, "灵草园", wild, 3, 4);
            world.addResourceNode(herbNode);
        }

        // 创建秘境资源点（产出混沌钟）
        Location dungeon = findLocationByType(world, LocationType.DUNGEON);
        if (dungeon != null) {
            world.addResourceNode(new ResourceNode(4, "上古遗迹", dungeon, 4, 12));
            world.addResourceNode(new ResourceNode(6, "秘境", dungeon, 5, 12));
            world.addResourceNode(new ResourceNode(7, "鬼蜮", dungeon, 6, 12));
            world.addResourceNode(new ResourceNode(8, "练符城", dungeon, 7, 12));
            world.addResourceNode(new ResourceNode(9, "高级练符城", dungeon, 8, 12));
        }
        // 创建矿山资源点（产出星辰铁）
        Location mine = findLocationByName(world, "矿山");
        if (mine != null) {
            ResourceNode mineNode = new ResourceNode(5, "矿脉", mine, 5, 5);
            world.addResourceNode(mineNode);
        }
    }

    public static void initializeLocations(WorldState world) {
        // 创建各种地点
        world.addLocation(new Location(1, "天元城", LocationType.CITY));
        world.addLocation(new Location(2, "迷雾森林", LocationType.WILD));
        world.addLocation(new Location(3, "古修士洞府", LocationType.DUNGEON));
        world.addLocation(new Location(4, "灵山", LocationType.WILD));
        world.addLocation(new Location(5, "醉仙楼", LocationType.TAVERN));
        world.addLocation(new Location(6, "百草谷", LocationType.WILD));
        world.addLocation(new Location(7, "炼丹房", LocationType.CITY));
        world.addLocation(new Location(8, "矿山", LocationType.WILD));
        world.addLocation(new Location(9, "剑冢", LocationType.DUNGEON));
    }

    // 辅助方法：按类型查找地点
    private static Location findLocationByType(WorldState world, LocationType type) {
        return world.getLocations().values().stream()
                .filter(l -> l.getType() == type)
                .findFirst()
                .orElse(null);
    }

    // 辅助方法：按名称查找地点
    private static Location findLocationByName(WorldState world, String name) {
        return world.getLocations().values().stream()
                .filter(l -> l.getName().equals(name))
                .findFirst()
                .orElse(null);
    }

}
